/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.moedik.classes;

import java.util.Calendar;

/**
 *
 * @author Yudi Retanto
 */
public class Kalender {

    protected Calendar currDate;
    protected String[] days = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"};
    protected String[] months = {"january", "february", "march", "april", "june", "july", "august", "september", "october", "november", "december"};

    public Kalender(Long milis) {
        this.currDate = Calendar.getInstance();
        this.currDate.setTimeInMillis(milis);
        this.currDate.set(Calendar.HOUR_OF_DAY, 0);            // set hour to midnight
        this.currDate.set(Calendar.MINUTE, 0);                 // set minute in hour
        this.currDate.set(Calendar.SECOND, 0);                 // set second in minute
        this.currDate.set(Calendar.MILLISECOND, 0);            // set millis in second
    }

    public Kalender() {
        this.currDate = Calendar.getInstance();
        this.currDate.set(Calendar.HOUR_OF_DAY, 0);            // set hour to midnight
        this.currDate.set(Calendar.MINUTE, 0);                 // set minute in hour
        this.currDate.set(Calendar.SECOND, 0);                 // set second in minute
        this.currDate.set(Calendar.MILLISECOND, 0);            // set millis in second
    }

    public Calendar getCurrDate() {
        return currDate;
    }

    public void setCurrDate(Calendar currDate) {
        this.currDate = currDate;
    }

    public int getDayOfWeek() {
        return this.currDate.get(Calendar.DAY_OF_WEEK);
    }

    public long getTomorrow() {
        Calendar to = Calendar.getInstance();
        to.setTimeInMillis(this.currDate.getTimeInMillis());
        to.add(Calendar.DAY_OF_WEEK, 1);
        return to.getTimeInMillis();
    }

    public long getYesterday() {
        Calendar to = Calendar.getInstance();
        to.setTimeInMillis(this.currDate.getTimeInMillis());
        to.add(Calendar.DAY_OF_WEEK, -1);
        return to.getTimeInMillis();
    }

    public int getDate() {
        return this.currDate.get(Calendar.DATE);
    }

    public int getMonth() {
        return this.currDate.get(Calendar.MONTH);
    }

    public int getYear() {
        return this.currDate.get(Calendar.YEAR);
    }

    public String getDayName() {
        return this.days[this.getDayOfWeek() - 1];
    }

    public String getMonthName() {
        return this.months[this.getMonth() - 1];
    }

    public boolean equalDate(Kalender kal) {
        if (kal.getYear() == this.getYear()) {
            if (kal.getMonth() == this.getMonth()) {
                if (kal.getDate() == this.getDate()) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isAMonthAfter() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, 30);
        return (cal.before(this.currDate)) ? true : false;
    }

    public boolean isToday() {
        Kalender cal = new Kalender();
        return (this.equalDate(cal)) ? true : false;
    }

    public long toMillis() {
        return this.currDate.getTimeInMillis();
    }

    public String toString() {
        return this.getDayName() + ", " + this.getDate() + " " + this.getMonthName() + " " + this.getYear();
    }
}
